<%@ page contentType="text/html;charset=UTF-8" %> 
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<c:if test="${companyList.editFlag == 1}">
               <title><spring:message code="company_edit_create"/><spring:message code="company_edit_edit"/></title>
    </c:if>
    <c:if test="${companyList.editFlag == 0 }">
               <title><spring:message code="company_edit_view" /><spring:message code="company_edit_ok" /></title>
    </c:if>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
   
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    
    <script type="text/javascript">
    
	 $(document).ready(function(){
		 var form = $("#inputForm");  
	        form.validate();//验证指定的表单
	        	/* $("#customerCategoryCD").select2();
	       	 	$("#customerLevelCD").select2(); */
	       	 	$("#companyCountry").select2();
	       		$("#companyCity").select2();
	       		if ('${companyList.editFlag == 0}') {
	       			$('.showHtml').find('input,select,textarea').attr('disabled','disabled');
				}
	        	$("#okButton").click(function(){
	        		if (form.valid()) {//如果表单验证成功，则进行提交。  
	        		$("#showHtml").addClass("showHtml");
	                $("#okHead").show();
	                $("#createHead").hide();
	                $("#operateP").hide();
	                $('tr').find('td:eq(0)').hide();
	                $("tr").children('th').eq(0).hide();	
	                $('.showHtml').find('input,select,textarea').attr('disabled',true);
	                return false;
	              }
	         });
	        	 
	    });
	 
	 /* 删除 银行账户 */
	 
	 function deleteCurrentRow(obj){ 
		 
		 if (confirm("<spring:message code="company_edit_areYouSure"/>")) {
            var tbody=obj.parentNode.parentNode.parentNode;  
            var table=tbody.parentNode;  
            table.removeChild(tbody);  
			
		}
	 }
        
	 /* 保存创建信息 */
    function createSaveForm(){
    	$('.showHtml').find('input,select,textarea').attr('disabled',false);
    	getList();
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/mycompany/message/createComSave",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		window.parent.frames[0].searchListForm();
    		closeWin();
    		
    	},'json');
    	
    }
    /* 保存编辑信息 */
    function editSaveForm(){
    	$('.showHtml').find('input,select,textarea').attr('disabled',false);
    	getList();
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/mycompany/message/editComSave",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		 window.parent.frames[0].searchListForm();
    	closeWin();
    		 
	
    	},'json');
    }
    
    
    function addBankCheck(obj) {
    
	/* 获取当前行的值 */
	
    var tr = obj.parentNode.parentNode;
	var index = tr.rowIndex;
    var bankAliias = $(tr).find('input#bankAliiasHere')[0].defaultValue;
    var bankPointName = $(tr).find('input#bankPointNameHere')[0].defaultValue;
    var bankName = $(tr).find('input#bankNameHere')[0].defaultValue;
    var bankAccountNo = $(tr).find('input#bankAccountNoHere')[0].defaultValue;
    var isDefault = $(tr).find('input#isDefaultHere')[0].defaultValue;
	var firstName = $("#firstName").val();
	popup('500px','324px','${ctx}/mycompany/message/addBank?bankAliias='+bankAliias+'&bankPointName='+bankPointName+'&bankName='+bankName+'&bankAccountNo='+bankAccountNo+'&isDefault='+isDefault+'&index='+index+'&firstName='+firstName);
	
    }
    	
    //城市联动
    function cityFun(t,id){
        var code=$(t).find("option:selected").attr("data-value");
        var param={"code":code};
        $.post("${ctx}/mycompany/message/city",param,function(result){
            var html="<option value=''><spring:message code="company_edit_pleaseChoose"/></option>";
            $.each(result,function(i,e){
                html+="<option value='"+e.itemCode+"-"+e.itemValue+"'>"+e.itemName+"</option>";
            });
            $("#"+id).html(html);
            $("#"+id).select2();
        },'json');
    }	
    	
    
    function getList() {
    	var bankAliias = document.getElementsByName("bankAliiasHere");
		var bankName = document.getElementsByName("bankNameHere");
    	var bankAccountNo = document.getElementsByName("bankAccountNoHere");
    	var bankPointName = document.getElementsByName("bankPointNameHere");
		var isDefault = document.getElementsByName("isDefaultHere");
    	var createAccountDate = document.getElementsByName("createAccountDateHere");
    	var createAccountUser = document.getElementsByName("createAccountUserHere");    	
    	var hiddenHtml = "";
		for (var i = 0; i < bankName.length; i++) {
			hiddenHtml+= "<input type='hidden' name='companyAccountList["+i+"].bankAliias' value='"+bankAliias[i].value+"'><input type='hidden' name='companyAccountList["+i+"].bankName' value='"+bankName[i].value+"'><input type='hidden' name='companyAccountList["+i+"].bankAccountNo' value='"+bankAccountNo[i].value+"'><input type='hidden' name='companyAccountList["+i+"].bankPointName' value='"+bankPointName[i].value+"'><input type='hidden' name='companyAccountList["+i+"].isDefault' value='"+isDefault[i].value+"'><input type='hidden' name='companyAccountList["+i+"].createAccountDate' value='"+createAccountDate[i].value+"'><input type='hidden' name='companyAccountList["+i+"].createAccountUser' value='"+createAccountUser[i].value+"'>";
		}
		$("#hiddenHtml").html(hiddenHtml);
	}
    </script>
</head>
<body>   
<form id="inputForm" name="inputForm">
<!-- 创建编辑头部 -->
<c:if test="${companyList.editFlag == 1}">
<div id="createHead" class="layerHeader clearfix">
	<c:choose>
	   <c:when test="${companyList.companyID!=null && companyList.companyID!=''}">
	    <!-- 编辑 --> 
			<p class="headerTitle"><spring:message code="company_edit_edit"/></p>
       </c:when>
       <c:otherwise>
        <!-- 创建 --> 
            <p class="headerTitle"><spring:message code="company_edit_create"/></p>
       </c:otherwise>
    </c:choose>
    <div class="headerButton clearfix">
        <!-- 确认 -->      
       	<button type="button" id="okButton" ><spring:message code="company_edit_ok"/></button>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="company_edit_cancle"/></button>
    </div>
</div>
<!-- 确认画面头部 -->
<div id="okHead" class="layerHeader clearfix" style="display: none;">	      
             <p class="headerTitle"><spring:message code="company_edit_ok" /></p>    
    <div class="headerButton clearfix">
    <shiro:hasPermission name="mycompany:message:edit">
    	<c:choose>
	  	 	<c:when test="${companyList.companyID!=null && companyList.companyID!=''}">
	  	 	 <!-- 编辑 保存 --> 
				<button type="button" onclick="editSaveForm()"><spring:message code="common_save" /></button>
      		 </c:when>
      		 <c:otherwise>
      	 	 <!-- 创建 保存 --> 
       	   		<button type="button" onclick="createSaveForm()"><spring:message code="common_save" /></button>
     	 	 </c:otherwise>
    	 </c:choose>
     </shiro:hasPermission>
          
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="company_edit_cancle"/></button>
    </div>
</div>
</c:if>
 <!-- 查看画面头部 -->
<c:if test="${companyList.editFlag == 0}">
<div id="viewHead" class="layerHeader clearfix" >
          <p class="headerTitle"><spring:message code="company_edit_view" /></p>
    <div class="headerButton clearfix">
    	<shiro:hasPermission name="mycompany:message:view">
        <!-- 编辑 -->
          <button type="button" onclick="popup('800px','519px','${ctx}/mycompany/message/editCom?companyID=${companyList.companyID}&editFlag=1');closeWin()">
               	<spring:message code="company_edit_edit" />
          </button>
        </shiro:hasPermission>
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="company_edit_cancle"/></button>
    </div>
</div>
</c:if>

<!-- 入力框 -->
<div style="overflow-y: auto;height: 480px;">
<div id="showHtml" class="tabBoxSm <c:if test="${companyList.editFlag == 0}">showHtml</c:if>" >
    <div class="tabSm smOrderBox">
        <div class="clearfix">
       <%--  <input type="hidden" id="companyType" name="companyType" value="${companyList.companyType}">
    	<input type="hidden" id="companyRank" name="companyRank" value="${companyList.companyRank}"> --%>
    	<input type="hidden" id="createDate" name="createDate" value="${fns:getDate('yyyy-MM-dd HH:mm')}">
    	<input type="hidden" id="createID" name="createID" value="${fns:getUser()}">
    	<input type="hidden" id="companyID" name="companyID" value="${companyList.companyID}">
        <input type="hidden" id="editFlag" name="editFlag" value="${companyList.editFlag}">
        	<div class="left">
        	
        	<c:if test="${companyList.companyID!=null && companyList.companyID!=''}">
        	   <!--  公司编号 -->
            	<div class="items clearfix">
                	<p class="tit"><spring:message code="company_edit_no"/></p>
                    <input id="companyNo" name="companyNo" style="border: none;color: #333;background-color: inherit;" disabled="true" value="${companyList.companyNo}" >
                    
                </div>
                </c:if>
                
               <!--  公司名称 -->
                <div class="items clearfix haveToBox">
                	<p class="tit"><spring:message code="company_edit_name"/></p>
                    <input id="companyName" name="companyName" maxlength="50" value="${companyList.companyName}" data-rule-required="true" data-msg-required="<spring:message code="company_edit_err_msg_companyName"/>">
                    <p class="haveTo">*</p>
                </div>
                
                <div class="items clearfix haveToBox">
                <c:set value="COUNTRIES_ID" var="countryList" />
                
                	<!--  所在国家 -->
                	<p class="tit"><spring:message code="company_edit_country"/></p>
                	<select id="companyCountry" name="companyCountry" onchange="cityFun(this,'companyCity')" style="width: 150px" data-rule-required="true" data-msg-required="<spring:message code="company_edit_err_msg_companyCountry"/>">
					<option value=""><spring:message code="company_edit_pleaseChoose"/></option>
					<c:forEach items="${fns:getDictList(countryList)}" var="Country">
                        <option data-value="${Country.itemValue}" value="${Country.itemCode}-${Country.itemValue}" <c:if test="${fn:split(companyList.companyCountry,'-')[1] eq Country.itemValue }">selected="selected"</c:if>>${Country.itemName}</option>
                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
                </div>
                
                <div class="items clearfix haveToBox">
                    <!--  所在城市 -->
                    <p class="tit"><spring:message code="company_edit_city"/></p>
                    <select id="companyCity" name="companyCity" style="width: 150px"  data-rule-required="true" data-msg-required="<spring:message code="company_edit_err_msg_companyCity"/>">
					<option value=""><spring:message code="company_edit_pleaseChoose"/></option>
					<c:forEach items="${fns:getDictList(fn:split(companyList.companyCountry,'-')[1])}" var="City">
                        <option value="${City.itemCode}-${City.itemValue}" <c:if test="${fn:split(companyList.companyCity,'-')[1] eq City.itemValue }">selected="selected"</c:if>>${City.itemName}</option>
                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
                </div>
                
                <!--  公司邮编 -->
                <div class="items clearfix">
                	<p class="tit"><spring:message code="company_edit_postCode"/></p>
                    <input id="companyPostCode" name="companyPostCode" style="ime-mode: disabled;" maxlength="20" value="${companyList.companyPostCode}">
                </div>
                <!--  公司地址 -->
                <div class="items clearfix">
                	<p class="tit"><spring:message code="company_edit_address"/></p>
                    <input id="companyAddress" name="companyAddress" style="width: 300px" maxlength="200" value="${companyList.companyAddress}" style="width: 230px">
                </div>
            </div>
            <div class="right">
            <%-- <!--  公司类别 -->
            	<div class="items clearfix haveToBox">
                	<p class="tit"><spring:message code="company_edit_type"/></p>
                	<c:set value="CUSTOMER_CATEGORY" var="customerCategoryList" />
					<select id="customerCategoryCD" name="customerCategoryCD" data-rule-required="true" data-msg-required="<spring:message code="company_edit_err_msg_companyType"/>">
					<option value=""><spring:message code="company_edit_pleaseChoose"/></option>
					<c:forEach items="${fns:getDictList(customerCategoryList)}" var="Category">
                        <option value="${Category.itemCode}-${Category.itemValue}" <c:if test="${fn:split(companyList.customerCategoryCD,'-')[1] eq Category.itemValue }">selected="selected"</c:if>>${Category.itemName}</option>
                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
                </div>
                <!--  公司等级 -->
                <div class="items clearfix haveToBox">
                	<p class="tit"><spring:message code="company_edit_level"/></p>
                    <c:set value="CUSTOMER_LEVEL" var="customerLevelList" />
                    <select id="customerLevelCD" name="customerLevelCD" data-rule-required="true" data-msg-required="<spring:message code="company_edit_err_msg_companyLevel"/>">
                    <option value=""><spring:message code="company_edit_pleaseChoose"/></option>
					<c:forEach items="${fns:getDictList(customerLevelList)}" var="Category">
                        <option value="${Category.itemCode}-${Category.itemValue}" <c:if test="${fn:split(companyList.customerLevelCD,'-')[1] eq Category.itemValue }">selected="selected"</c:if>>${Category.itemName}</option>
                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
                </div> --%>
                
                <!--  公司简称  -->
                <div class="items clearfix haveToBox">
                	<p class="tit"><spring:message code="company_edit_shortName"/></p>
                    <input id="companyShortName" name="companyShortName" style="ime-mode: disabled;" maxlength="4" onKeyUp="value=value.replace(/[^a-zA-Z]/g,'')" value="${companyList.companyShortName}" data-rule-required="true" data-msg-required="<spring:message code="company_edit_err_msg_companyShortName"/>">
                    <p class="haveTo">*</p>
                </div>
                
               <!--  公司简介 -->
               <div class="items clearfix">
                	<p class="tit"><spring:message code="company_edit_remark"/></p>
                    <textarea id="companyRemark" name="companyRemark" style="width: 300px;height: 150px;">${companyList.companyRemark}</textarea>
                </div>
            </div>
       
        </div> 
	</div>
    
	<!-- 银行账户信息 -->
	
    <div class="">
	
    	<div class="tableArea">
			<div class="">
				<div style="float: left;">
				<p class="tit"><spring:message code="company_edit_bankAccount"/></p>
				</div>
				<div style="float: right;">
				<c:if test="${companyList.editFlag == 1}">
				<a href="###" id="operateP" onclick="popup('500px','324px','${ctx}/mycompany/message/addBank')"><spring:message code="company_edit_createBankAccount"/></a>
				</c:if>   
				</div>
			</div>
        	<div class="tableScroll tableScrollSm" style="padding-top: 5px">
        		<table cellpadding="0" class="" name ="perantTable" id ="perantTable">
                    <tr>
                     <c:if test="${companyList.editFlag == 1}">
                    	<th id="operateTh" class="table-gszhcz"><spring:message code="company_edit_operate"/></th>
                     </c:if>    
                        <th class="table-gszhzhbc"><spring:message code="company_edit_bankAliias"/></th>
                        <th class="table-gszhkhmc"><spring:message code="company_edit_bankName"/></th>
                        <th class="table-gszhkhzh"><spring:message code="company_edit_bankAccountNo"/></th>
                        <th class="table-gszhkhwd"><spring:message code="company_edit_bankPointName"/></th>
                        <th class="table-gszhzhlx"><spring:message code="company_edit_accountType"/></th>
                        <th class="table-gszhkhr"><spring:message code="company_edit_createAccountUser"/></th>
                        <th class="table-gszhkhsj"><spring:message code="company_edit_createAccountDate"/></th>
                    </tr>
         		<c:forEach items="${companyList.companyAccountList}" var="companyAccount" varStatus="status">
				  <c:if test="${not empty companyAccount}">
                    <tbody >
                    <tr>
                     <c:if test="${companyList.editFlag == 1}">
                    	<td class="table-gszhcz"><img src="${ctxStatic}/images/btn-bj.png" onclick="addBankCheck(this)" height="30" width="30">&nbsp;&nbsp;<img src="${ctxStatic}/images/btn-sc.png" height="30" width="30"  onclick="deleteCurrentRow(this)"></td>
                     </c:if>   
                        <td class="table-gszhzhbc">${companyAccount.bankAliias }</td>
                        <td class="table-gszhkhmc">${companyAccount.bankName }</td>
                        <td class="table-gszhkhzh">${companyAccount.bankAccountNo }</td>
                        <td class="table-gszhkhwd">${companyAccount.bankPointName }</td>
                        <td class="table-gszhzhlx"><c:if test="${companyAccount.isDefault==1}"><spring:message code="company_account_defaultAccount"/></c:if><c:if test="${companyAccount.isDefault==0}"><spring:message code="company_account_notDefaultAccount"/></c:if></td>
                        <td class="table-gszhkhr">${companyAccount.createBy.firstName }</td>
                        <td class="table-gszhkhsj" ><fmt:formatDate value="${companyAccount.createAccountDateDB }" pattern="yyyy-MM-dd HH:mm" /></td>
                        <input type="hidden" id="bankAliiasHere" name="bankAliiasHere" value="${companyAccount.bankAliias }">
                        <input type="hidden" id="bankNameHere" name="bankNameHere" value="${companyAccount.bankName }">
                        <input type="hidden" id="bankAccountNoHere" name="bankAccountNoHere" value="${companyAccount.bankAccountNo }">
                        <input type="hidden" id="bankPointNameHere" name="bankPointNameHere" value="${companyAccount.bankPointName }">
                        <input type="hidden" id="isDefaultHere" name="isDefaultHere" value="${companyAccount.isDefault }">
                        <input type="hidden" id="createAccountDateHere" name="createAccountDateHere" value="${companyAccount.createAccountDate }">
                        <input type="hidden" id="createAccountUserHere" name="createAccountUserHere" value="${companyAccount.createAccountUser }">
                    </tr>
                	</tbody>
                  </c:if>
                </c:forEach>
                </table>
                <div id="hiddenHtml"></div>
            </div>
        </div>
    </div>
</div>
</div>  
</form>
<script>
</script>
</body>
</html>
